﻿#include "stdafx.h"
#include "GameSystem.h"

void GameSystem::NewGame()
{
	//TODO:根据用户选择来构成雷区，主要是块数，块大小的算法和界面整理算法需要进一步完善。
	//BAC.ClearBlocks();
	BAC.BindWindow( m_pParent );
	BAC.CreateBlocks( 20, 18, 12, 30, 30 , 10 , 00 );
	m_pParent->Invalidate();
}

void GameSystem::ReSetGame()
{
	BAC.HideArea();
	m_pParent->Invalidate();
}

void GameSystem::ButtonEvent( UINT uId, ButtonEventId EventId )
{
	switch (EventId)
	{
	case LEFT_CLICK_BLOCK:
		
		BAC.CheckMine(uId);
		break;
	case RIGHT_CLICK_BLOCK:
		BAC.CheckedBlock(uId);
		break;
	case LEFT_RIGHT_CLICK_BLOCK:
		BAC.LRButtonCheackMine(uId);
		break;
	case LEFT_DOWN:
		BAC.PressDown(uId);
		break;
	case LEFT_UP:
		BAC.ReleasUp(uId);
		break;
	case LEFT_RIGHT_DOWN:
		BAC.LRPressDown(uId);
		break;
	case LEFT_RIGHT_UP:
		BAC.LRReleasUp(uId);
		break;
	case LEFT_DOWN_CHECK:
		BAC.CheckBlockLDown(uId);
		break;
	case RIGHT_DOWN_CHECK:
		BAC.CheckBlockRDown(uId);
		break;
	default:
		AfxMessageBox(_T("此事件没有注册!"));
	}
	HandlingEvents();
}

void GameSystem::HandlingEvents()
{
	int iRetVal;
	switch( BAC.GetLastEvent() ){
	case AE_BOMB_BOOM:
		iRetVal = m_pParent->MessageBox( _T("踩雷啦！\n再来一次？") , _T("") , MB_YESNO|MB_ICONEXCLAMATION );
		if( IDYES == iRetVal )
			BAC.ResetBlocks();
		break;
	default:

		break;
	}


	BAC.ClearEvent();
}
